package com.itboye.lottery.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableRow;
import android.widget.TextView;

import com.itboye.bylibrary.util.TimeUtils;
import com.itboye.lottery.R;
import com.itboye.lottery.bean.NoticeBean;

import java.util.ArrayList;

/**
 * Created by wu on 2018/1/9.
 */

public class ZqNoticeDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    ArrayList<NoticeBean.NoticeItem> classEntityArrayList;
    Activity activity;

    public ZqNoticeDetailAdapter(Activity Activity, ArrayList<NoticeBean.NoticeItem> classEntityArrayList) {
        this.activity = Activity;
        this.classEntityArrayList = classEntityArrayList;
    }

    public OnItemClickListener itemClickListener;

    public void setOnItemClickListener(ZqNoticeDetailAdapter.OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ViewHolderAnnouncementZqDetail(LayoutInflater.from(context).inflate(R.layout.item_zq_notice_detail, parent, false));
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolderAnnouncementZqDetail viewHolderAnnouncementZqDetail = (ViewHolderAnnouncementZqDetail) holder;
        NoticeBean.NoticeItem noticeItem = classEntityArrayList.get(position);
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_1.setText(Html.fromHtml(noticeItem.getL_cn_abbr() + "<br />" + noticeItem.getNum() + "<br />" + TimeUtils.getFormatTime(Long.parseLong(noticeItem.getBegin_time()), "HH:mm")));
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_2.setText(noticeItem.getH_cn_abbr());
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_3.setText(Html.fromHtml("<font color='red'>" + noticeItem.getFinal_score() + "</font><br />半场" + noticeItem.getHalf_score()));
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_4.setText(noticeItem.getA_cn_abbr());


        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_spf.setText(noticeItem.getWin());
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_rq.setText("(" + noticeItem.getLet_score() + ")" + noticeItem.getJieguo());
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_bf.setText(noticeItem.getFinal_score());
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_zjq.setText(noticeItem.getZong() + "");
        viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_bqc.setText(noticeItem.getBanquan());

        if (noticeItem.getType().equals("2")) {//篮球
            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_bqc.setVisibility(View.GONE);
            viewHolderAnnouncementZqDetail.item_tb_zq_notice_detail_title.getChildAt(4).setVisibility(View.GONE);
            ((TextView) viewHolderAnnouncementZqDetail.item_tb_zq_notice_detail_title.getChildAt(0)).setText("胜负");
            ((TextView) viewHolderAnnouncementZqDetail.item_tb_zq_notice_detail_title.getChildAt(1)).setText("让分");
            ((TextView) viewHolderAnnouncementZqDetail.item_tb_zq_notice_detail_title.getChildAt(2)).setText("大小分");
            ((TextView) viewHolderAnnouncementZqDetail.item_tb_zq_notice_detail_title.getChildAt(3)).setText("胜负差");
            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_spf.setText(TextUtils.isEmpty(noticeItem.getWin()) ? "-" : noticeItem.getWin());
            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_rq.setText(TextUtils.isEmpty(noticeItem.getLet_score()) ? "-" : noticeItem.getLet_score());
            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_bf.setText(noticeItem.getZong() == 0 ? "-" : noticeItem.getZong() + "");
            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_zjq.setText(TextUtils.isEmpty(noticeItem.getVictory()) ? "-" : noticeItem.getVictory());

            viewHolderAnnouncementZqDetail.item_tv_zq_notice_detail_3.setText(Html.fromHtml("<font color='red'>" + noticeItem.getFinal_score() + "</font>"));
        } else {//足球
        }
    }

    @Override
    public int getItemCount() {
        return classEntityArrayList == null ? 0 : classEntityArrayList.size();
    }

    public class ViewHolderAnnouncementZqDetail extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView item_tv_zq_notice_detail_1, item_tv_zq_notice_detail_2, item_tv_zq_notice_detail_3, item_tv_zq_notice_detail_4;

        TextView item_tv_zq_notice_detail_spf, item_tv_zq_notice_detail_rq, item_tv_zq_notice_detail_bf, item_tv_zq_notice_detail_zjq, item_tv_zq_notice_detail_bqc;

        TableRow item_tb_zq_notice_detail_title;

        public ViewHolderAnnouncementZqDetail(View itemView) {
            super(itemView);
            item_tv_zq_notice_detail_1 = itemView.findViewById(R.id.item_tv_zq_notice_detail_1);
            item_tv_zq_notice_detail_2 = itemView.findViewById(R.id.item_tv_zq_notice_detail_2);
            item_tv_zq_notice_detail_3 = itemView.findViewById(R.id.item_tv_zq_notice_detail_3);
            item_tv_zq_notice_detail_4 = itemView.findViewById(R.id.item_tv_zq_notice_detail_4);
            item_tv_zq_notice_detail_spf = itemView.findViewById(R.id.item_tv_zq_notice_detail_spf);
            item_tv_zq_notice_detail_rq = itemView.findViewById(R.id.item_tv_zq_notice_detail_rq);
            item_tv_zq_notice_detail_bf = itemView.findViewById(R.id.item_tv_zq_notice_detail_bf);
            item_tv_zq_notice_detail_zjq = itemView.findViewById(R.id.item_tv_zq_notice_detail_zjq);
            item_tv_zq_notice_detail_bqc = itemView.findViewById(R.id.item_tv_zq_notice_detail_bqc);
            item_tb_zq_notice_detail_title = itemView.findViewById(R.id.item_tb_zq_notice_detail_title);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (itemClickListener != null) {
                itemClickListener.onItemClick(v, getAdapterPosition());
            }
        }
    }

}
